package io.renren.common.utils.test;

import java.util.Scanner;

public class ErFenFa {

    static int N=100010;
    static int[] arr=new int[N];
    static int n,m;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        int max=0;
        int sum=0;
        for(int i=1;i<=n;++i) {
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max, arr[i]);
        }
        int l=max;
        int r=sum;
        while(l<r) {
            int mid=(l+r)>>1;
            if(check(mid)) r=mid;
            else l=mid+1;
        }
        System.out.println(l);
    }
    static boolean check(int target) {
        int count=0;
        int tmp=0;
        for(int i=1;i<=n;++i) {
            count+=arr[i];
            if(count>target){
                count=0;
                tmp++;
                i--;
            }else if(i==n){
                tmp++;
            }
        }
        return tmp<=m;
    }
}
